package com.imooc.concurrent.base;

//军队线程
//模拟作战双方行为
public class ArmyRunnable implements Runnable {
	//volatile保证线程可以正确的读取其他线程写入的值
	volatile boolean keepRunning = true;

	@Override
	public void run() {

		while(keepRunning){
			//发动5连击
			for(int i=0;i<5;i++){
				System.out.println(Thread.currentThread().getName()+"进攻对方["+i+"]");
				//让出处理器
				Thread.yield();
			}
		}
		System.out.println(Thread.currentThread().getName()+"结束了战斗");
	}

}
